/**
 * @describe 通过业务类型，设置获取未完成订单和放弃订单的接口地址
 * @param { String } (businessType) 业务类型
**/
export const getOrderGetAndAbandonUrl = (businessType) => {
    let requestUrl = {};

    // 开成卡、开白卡、开空卡
    if (
        businessType === 'CARD' ||
        businessType === 'OPEN_CHENG' ||
        businessType === 'OPEN_WHITE'
    ) {
        requestUrl = {
            get: '/eas/w/searchcard/getOrder',
            abandon: '/eas/w/searchcard/orderCancel'
        }
    } else if (businessType === 'MAKE_CHENG') {
        requestUrl = {
            get: '/eas/w/adult/getOrder',
            abandon: '/eas/w/adult/closeOrder'
        }
    } else if (businessType === 'MAKE_WHITE') {
        requestUrl = {
            get: '/eas/w/white/getOrder',
            abandon: '/eas/w/white/closeOrder'
        }
    }

    return requestUrl;
}
/**
 * @describe 通过业务类型，设置未完成订单的订单缓存信息
 * @param { String } (businessType) 业务类型
 * @param { Object } (vm) vue实例
**/
export const setOrderStore = (vm, businessType, orderInfo = {}) => {
    // 开成卡、开白卡、开空卡
    // if (
    //     businessType === 'CARD' ||
    //     businessType === 'OPEN_CHENG' ||
    //     businessType === 'OPEN_WHITE'
    // ) {
    //     userData.idName = orderInfo.x;
    //     userData.idName = orderInfo.x;
    //     userData.idName = orderInfo.x;
    //     userData.idName = orderInfo.x;
    // }
    // // 制成卡、制白卡
    // else if (
    //     businessType === 'MAKE_CHENG' ||
    //     businessType === 'MAKE_WHITE'
    // ) {

    // }


    vm.setStore('KM_ORDER_INFO', orderInfo)
}

/**
 * @describe 订单初始化
 * @param { Object } (vm) vue实例
**/
export const orderInit = (vm) => {
    vm.removeStore('DEVICE_INFO');
    vm.removeStore('KM_ORDER_INFO');
    vm.removeStore('USER_DATA');
}

/**
 * @describe 通过业务类型，设置未完成订单的订单状态,并返回订单的下一步url
 * @param { String } (businessType) 业务类型
 * @param { Object } (vm) vue实例
**/
export const setOrderStatus = (businessType, orderInfo = {}) => {
    let statusDesc = '', url = '', title = '';
    // 开卡系列
    if (
        businessType === 'CARD' ||
        businessType === 'OPEN_CHENG' ||
        businessType === 'OPEN_WHITE'
    ) {
        switch (orderInfo.orderStatusCode) {
            case '1001':
                statusDesc = '<b class="yellow">待实名认证</b>';
                url = '../cardProcess/real-name.html';
                title = '实名认证';
                break;
            case '1003':
                // 待审核
                if (
                    orderInfo.auditOrPay == 1 ||
                    orderInfo.actualMoney === '0'
                ) {
                    statusDesc = '<b class="yellow">待审核</b>';
                    url = '../cardProcess/audit.html';
                    title = '开卡资料提交';
                } else {
                    statusDesc = '<b class="yellow">待支付</b>';
                    url = '../cardProcess/pay.html';
                    title = '支付';
                }
                break;
            case '1004':
                // 已支付完成
                statusDesc = '<b class="yellow">待生成受理单</b>';
                url = '../cardProcess/pay.html';
                title = '支付';
                break;
            case '1006':
                statusDesc = '<b class="yellow">待写卡</b>';
                url = '../cardProcess/write-in.html';
                title = '写卡';
                break;
            // case '1007':
            //     statusDesc = '<b class="yellow">受理单处理中</b>';
            //     url = '../cardProcess/pay.html';
            //     title = '生成受理单';
            // break;
            case '1007': case '1008':
                statusDesc = '<b class="yellow">待写卡</b>';
                url = '../cardProcess/write-in.html';
                title = '写卡';
                break;
            default:
                statusDesc = '--'
                break;
        }
    }
    // 制卡系列
    else if (
        businessType === 'MAKE_CHENG' ||
        businessType === 'MAKE_WHITE'
    ) {
        let orderStatus = orderInfo.orderStatus;

        switch (orderStatus) {
            case 'CREATED':
                statusDesc = '<b class="yellow">待实名认证</b>';
                url = '../makeProcess/real-name.html';
                title = '机主预留信息';
                break;
            case 'NOT_PAY':
                statusDesc = '<b class="yellow">待支付</b>';
                url = '../makeProcess/pay.html';
                title = '支付';
                break;
            case 'PAYED': case 'GOTIMSI':
                statusDesc = '<b class="yellow">待制卡</b>';
                url = '../makeProcess/write-in.html';
                title = '制卡';
                break;
            default:
                statusDesc = '--'
                break;
        }

    }

    return {
        statusDesc,
        url,
        title
    };
}

/**
 * @describe 设置补换卡未完成订单的订单状态,并返回订单的下一步url
 * @param { String } (businessType) 业务类型
 * @param { Object } (vm) vue实例
**/
export const setCardReplaceOrderStatus = (orderInfo = {}) => {
    let statusDesc = '', url = '', title = '';

    switch (orderInfo.orderStatusCode) {
        case '1001':
            statusDesc = '待实名认证';
            url = '../cardReplace/audit.html';
            title = '补换卡资料提交';
            break;
        case '1002': case '1003':
            statusDesc = '待生成受理单';
            url = '../cardReplace/audit.html';
            title = '生成受理单';
            break;
        case '1004': case '1005':
            statusDesc = '待写卡';
            url = '../cardReplace/write-in.html';
            title = '写卡';
            break;
        default:
            statusDesc = '--'
            break;
    }

    return {
        statusDesc,
        url,
        title
    };
}

/**
 * @describe 上传设备使用记录
 * @param { Object } (vm) vue实例
 * @param { Object } (params) 上传参数
**/
export function uploadDeviceLog (vm, params) {
    let json = {
        userInfo: vm.userInfo,
        params: {
            logList: [
                Object.assign({
                    result: params.errorMsg ? '0' : '1', // 0失败1成功
                    timestamp: vm.getTimestamp(),
                    deviceId: '1',
                    deviceName: vm.deviceInfo.deviceName,
                }, params)
            ]
        }
    };

    // return new Promise((resolve) => {
    vm.AJAX('/eas/c/devicelog/add', json, function (res) {
        // if (res) {
        // 	resolve(true);
        // }
    }, true, true);
    // })
}
/**
 * @describe 上传活体识别使用记录
 * @param { Object } (vm) vue实例
 * @param { Object } (params) 上传参数
**/
export function uploadFaceVerificationLog (vm, params) {
    let json = {
        userInfo: vm.userInfo,
        params: {
            logList: [
                Object.assign({
                    result: params.errorMsg ? '0' : '1', // 0失败1成功
                    timestamp: vm.getTimestamp(),
                    deviceId: '2',
                    deviceName: '腾讯云',
                }, params)
            ]
        }
    };

    // return new Promise((resolve) => {
    vm.AJAX('/eas/c/devicelog/upload', json, function (res) {
        // if (res) {
        // 	resolve(true);
        // }
    }, true, true);
    // })
}
/**
 * @describe 上传写卡使用记录
 * @param { Object } (vm) vue实例
 * @param { Object } (params) 上传参数
**/
export function uploadWriteInLog (vm, params) {
    let json = {
        userInfo: vm.userInfo,
        params: {
            logList: [
                Object.assign({
                    result: params.errorMsg ? '0' : '1', // 0失败1成功
                    timestamp: vm.getTimestamp(),
                    deviceId: '1',
                    deviceName: vm.deviceInfo.deviceName,
                }, params)
            ]
        }
    };

    // return new Promise((resolve) => {
    vm.AJAX('/eas/c/devicelog/writecard', json, function (res) {
        // if (res) {
        // 	resolve(true);
        // }
    }, true, true);
    // })
}